package com.seeyon.apps.kk.manager;

import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.axis2.AxisFault;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hamcrest.core.Is;
import org.springframework.dao.DataAccessException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.seeyon.apps.kk.manager.datasync.AbstractDataSyncManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.organization.bo.OrganizationMessage;
import com.seeyon.ctp.organization.bo.V3xOrgDepartment;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.organization.manager.OrgManagerDirect;
import com.seeyon.kk.utils.MapToLowerCaseUtils;

import jersey.repackaged.com.google.common.collect.Maps;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertAnnualAssessVO;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertAnnualAssessVOResponse;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertEmployeeAbilityTestVO;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertEmployeeAbilityTestVOResponse;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertNewEmployeeTestVO;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertNewEmployeeTestVOResponse;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertSkillVO;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertSkillVOResponse;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertTechVO;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.BatchInsertTechVOResponse;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.VacationInsert;
import nc.itf.hr.hi.ipsndocinfoservice.IPsndocInfoServiceStub.VacationInsertResponse;
import nc.itf.ly_ext.webservice.isyncapply.ISyncApplyStub;
import nc.itf.ly_ext.webservice.isyncapply.ISyncApplyStub.Apply;
import nc.itf.ly_ext.webservice.isyncapply.ISyncApplyStub.ApplyResponse;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.ContractRenewal;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.ContractRenewalResponse;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.CreateOrder;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.CreateOrderResponse;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.EmployeeCardSync;
import nc.itf.ly_ext.webservice.lyandoabuttservice.LyAndOAButtServiceStub.EmployeeCardSyncResponse;
import nc.itf.ly_ext.webservice.lybusiwebserviceitf.LyBusiWebServiceItfStub;
import nc.itf.ly_ext.webservice.lybusiwebserviceitf.LyBusiWebServiceItfStub.SupplierStatus;
import nc.itf.ly_ext.webservice.lybusiwebserviceitf.LyBusiWebServiceItfStub.SupplierStatusResponse;

/**
 * 通用监听实现类
 * 
 * @author
 *
 */
public class TemplateTongManagerImpl extends AbstractDataSyncManager {

	private static final Log log = LogFactory.getLog(TemplateTongManagerImpl.class);

	private DataPushLogManageImpl logManageImpl = (DataPushLogManageImpl) AppContext.getBean("dataPushLogManageImpl");

	private FreemarkFlowManager freemarkFlowManager;

	public OrganizationMessage getOrganizationMessage() {
		return organizationMessage;
	}

	public void setOrganizationMessage(OrganizationMessage organizationMessage) {
		this.organizationMessage = organizationMessage;
	}

	public OrgManager getOrgManager() {
		return orgManager;
	}

	public void setOrgManager(OrgManager orgManager) {
		this.orgManager = orgManager;
	}

	public OrgManagerDirect getOrgManagerDirect() {
		return orgManagerDirect;
	}

	public void setOrgManagerDirect(OrgManagerDirect orgManagerDirect) {
		this.orgManagerDirect = orgManagerDirect;
	}

	private OrganizationMessage organizationMessage;

	private OrgManager orgManager;

	private OrgManagerDirect orgManagerDirect;

	// NC 接口调用类
	LyAndOAButtServiceStub stub = null;

	IPsndocInfoServiceStub iVacationServiceStub = null;

	LyBusiWebServiceItfStub busiWebServiceItfStub = null; // 供应商单据接口

	public FreemarkFlowManager getFreemarkFlowManager() {
		return freemarkFlowManager;
	}

	public void setFreemarkFlowManager(FreemarkFlowManager freemarkFlowManager) {
		this.freemarkFlowManager = freemarkFlowManager;
	}

	/**
	 * OA上岗证信息推送至NC
	 * 
	 * @return
	 */
	public void sendTONCEmployeeCard(Map<String, Object> parmas) {
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/employeeCard/SELECT_EMPCARD_SQL.ftl",
					parmas);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			stub = new LyAndOAButtServiceStub();
			for (Map<String, Object> map : array) {
				EmployeeCardSync employeeCardSync6 = new EmployeeCardSync();
				map.put("corp", "01");
				map.put("ZSTYPE", MapUtils.getString(map, "ZSTYPE") == null ? "01" : MapUtils.getString(map, "ZSTYPE"));
				map.put("MEMO1", MapUtils.getString(map, "MEMO1") == null ? "" : MapUtils.getString(map, "MEMO1"));
				map.put("MEMO2", MapUtils.getString(map, "MEMO2") == null ? "" : MapUtils.getString(map, "MEMO2"));
				map.put("MEMO3", MapUtils.getString(map, "MEMO3") == null ? "" : MapUtils.getString(map, "MEMO3"));
				map.put("MEMO4", MapUtils.getString(map, "MEMO4") == null ? "" : MapUtils.getString(map, "MEMO4"));
				map.put("MEMO5", MapUtils.getString(map, "MEMO5") == null ? "" : MapUtils.getString(map, "MEMO5"));
				map.put("VMEMO", MapUtils.getString(map, "VMEMO") == null ? "" : MapUtils.getString(map, "VMEMO"));
				List<Map<String, Object>> list = new ArrayList<>();
				list.add(MapToLowerCaseUtils.mapToLower(map));//
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
				employeeCardSync6.setString(JSON.toJSONString(list));
				EmployeeCardSyncResponse rs = stub.employeeCardSync(employeeCardSync6);
				// 更新抛送数据
				logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
				log.info("上岗证抛送NC数据：" + JSON.toJSONString(list));
				log.info("=================上岗证=======================\n" + rs.get_return());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCInspectionCycle()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 外场信息通知单
	 * 
	 * @param parmas
	 */
	public void sendTONCWorkOrder(Map<String, Object> parmas) {
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workorder/SELECT_ORDER_SQL.ftl", parmas);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			stub = new LyAndOAButtServiceStub();
			for (Map<String, Object> map : array) {
				// 获取表单发起人 code and dept code
				V3xOrgMember member = this.orgManager.getMemberById(MapUtils.getLong(map, "memberId"));
				V3xOrgDepartment department = this.orgManager.getDepartmentById(member.getOrgDepartmentId());
				map.put("pgdept", department.getCode());
				map.put("pgpsn", member.getCode());
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				map.put("BILLDATE", dateFormat.format(dateFormat.parse(MapUtils.getString(map, "BILLDATE"))));
				CreateOrder createOrder0 = new CreateOrder();
				log.info("外场信息通知单抛送NC数据：" + JSON.toJSONString(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
				createOrder0.setString(JSON.toJSONString(MapToLowerCaseUtils.mapToLower(map)));
				CreateOrderResponse rs = stub.createOrder(createOrder0);
				// 更新抛送数据
				logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
				log.info("=================外场信息通知单=====================\n" + rs.get_return());

			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCWorkOrder()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 专业技术职务聘任审批表 数据
	 * 
	 * @param parmas
	 */
	public void sendTONCBatchInsertTechVO(Map<String, Object> parmas) {
		String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_ZYJS_ZWPR_SQL.ftl", parmas);
		log.info("专业技术职务聘任审批表SQL:" + sql);
		try {
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			for (Map<String, Object> map : array) {
				sendData.add(MapToLowerCaseUtils.mapToLower(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			log.info("专业技术职务聘任审批表,FORMMAIN_1317,\n推送数据：" + JSONArray.toJSONString(sendData));
			BatchInsertTechVO batchInsertTechVO8 = new BatchInsertTechVO();
			batchInsertTechVO8.setString(JSONArray.toJSONString(sendData));
			BatchInsertTechVOResponse rs = iVacationServiceStub.BatchInsertTechVO(batchInsertTechVO8);
			// 更新抛送数据
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("=================专业技术职务聘任审批表=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCBatchInsertTechVO()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 职业技能等级晋升审批表
	 * 
	 * @param parmas
	 */
	public void sendTONCBatchInsertSkillVO(Map<String, Object> parmas) {
		String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_ZYJS_GRADE_SQL.ftl",
				parmas);
		log.info("职业技能等级晋升审批表SQL:" + sql);
		try {
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			for (Map<String, Object> map : array) {
				sendData.add(MapToLowerCaseUtils.mapToLower(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			BatchInsertSkillVO batchInsertSkillVO0 = new BatchInsertSkillVO();
			log.info("专业技术职务聘任审批表,FORMMAIN_0698 \n推送数据：" + JSONArray.toJSONString(sendData));
			batchInsertSkillVO0.setString(JSONArray.toJSONString(sendData));
			BatchInsertSkillVOResponse rs = iVacationServiceStub.BatchInsertSkillVO(batchInsertSkillVO0);
			// 更新抛送数据
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("=================职业技能等级晋升审批表=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCBatchInsertSkillVO()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 新职工考核评价表
	 * 
	 * @param parmas
	 */
	public void sendTONCBatchInsertNewEmployeeVO(Map<String, Object> parmas) {
		String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_STAFF_001_SQL.ftl", parmas);
		log.info("新职工考核评价表SQL:" + sql);
		try {
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			for (Map<String, Object> map : array) {
				sendData.add(MapToLowerCaseUtils.mapToLower(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			log.info("新职工考核评价表,FORMMAIN_1671 \n推送数据：" + JSONArray.toJSONString(sendData));
			BatchInsertNewEmployeeTestVO batchInsertNewEmployeeTestVO10 = new BatchInsertNewEmployeeTestVO();
			batchInsertNewEmployeeTestVO10.setString(JSONArray.toJSONString(sendData));
			BatchInsertNewEmployeeTestVOResponse rs = iVacationServiceStub
					.BatchInsertNewEmployeeTestVO(batchInsertNewEmployeeTestVO10);
			// 更新抛送数据
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("=================新职工考核评价表=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCBatchInsertNewEmployeeVO()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 劳动合同续签
	 * 
	 * @param parmas
	 */
	public void sendTONCContractRenewal(Map<String, Object> parmas) {
		String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/contract/SELECT_RENEWAL_CONTRACT_SQL.ftl",
				parmas);
		log.info("劳动合同续签SQL:" + sql);
		try {
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			stub = new LyAndOAButtServiceStub();
			ContractRenewal contractRenewal14 = new ContractRenewal();
			boolean flag = false; // true 全部通过
			for (Map<String, Object> map : array) {
				// 所在部门意见 通过
				if (StringUtils.equals(MapUtils.getString(map, "depttype"), "2819448055794911778")) {
					// 单位意见 通过
					if (!StringUtils.equals(MapUtils.getString(map, "membertype"), "3285770352634121001")) {
						// 3285770352634121001 不同意，
						map.put("cont_unit", "1"); // 1、年，2、月，3、日
						if (StringUtils.equals(MapUtils.getString(map, "membertype"), "5408376059772619448")) {
							// 固定期限
							map.put("termtype", "CM01"); // 固定期限
							map.put("termmonth", "5"); // 5年
						} else if (StringUtils.equals(MapUtils.getString(map, "membertype"), "7641684015744893493")) {
							// 无固定期限
							map.put("termtype", "CM02"); // 无固定期限
						}
						sendData.add(MapToLowerCaseUtils.mapToLower(map));
						flag = true;
						// 抛送数据写入日志底表 第一次添加
						if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
							logManageImpl.sendLog(parmas, JSON.toJSONString(map));
						}
					}
				}
			}
			if (flag) {
				log.info("劳动合同续签抛送NC数据：\n" + JSONArray.toJSONString(sendData));
				contractRenewal14.setString(JSONArray.toJSONString(sendData));
				ContractRenewalResponse rs = stub.contractRenewal(contractRenewal14);
				logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
				log.info("=================劳动合同续签=====================\n" + rs.get_return());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCContractRenewal()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 职工能力考评（专业技术类）、（操作和辅助类）
	 * 
	 * @param parmas
	 */
	public void sendTONCBatchInsertAbilityVO(Map<String, Object> parmas) {
		String sql = "";
		if (StringUtils.equals(MapUtils.getString(parmas, "type"), "y")) {
			// （专业技术类）
			sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_STAFF_002_SQL.ftl", parmas);
		} else {
			// （操作和辅助类）
			sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_STAFF_003_SQL.ftl", parmas);
		}
		try {
			log.info("职工能力考评SQL:" + sql);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			for (Map<String, Object> map : array) {
				sendData.add(MapToLowerCaseUtils.mapToLower(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			BatchInsertEmployeeAbilityTestVO batchInsertEmployeeAbilityTestVO2 = new BatchInsertEmployeeAbilityTestVO();
			log.info("职工能力考评 \n推送数据：" + JSONArray.toJSONString(sendData));
			batchInsertEmployeeAbilityTestVO2.setString(JSONArray.toJSONString(sendData));
			BatchInsertEmployeeAbilityTestVOResponse rs = iVacationServiceStub
					.BatchInsertEmployeeAbilityTestVO(batchInsertEmployeeAbilityTestVO2);
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("=================职工能力考评=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCBatchInsertNewEmployeeVO()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 职工年度考核登记表
	 * 
	 * @param parmas
	 */
	public void sendTONCBatchInsertAnnualAssessVO(Map<String, Object> parmas) {
		String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_STAFF_004_SQL.ftl", parmas);
		log.info("职工年度考核登记表SQL:" + sql);
		try {
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> sendData = Lists.newArrayList();
			for (Map<String, Object> map : array) {
				int max = 0;
				String key = "";
				Map<String, Integer> maxMap = Maps.newHashMap();
				maxMap.put("优秀",
						MapUtils.getInteger(map, "FIELD0024") == null ? 0 : MapUtils.getInteger(map, "FIELD0024"));
				maxMap.put("称职",
						MapUtils.getInteger(map, "FIELD0025") == null ? 0 : MapUtils.getInteger(map, "FIELD0025"));
				maxMap.put("不称职",
						MapUtils.getInteger(map, "FIELD0026") == null ? 0 : MapUtils.getInteger(map, "FIELD0026"));
				for (String temp : maxMap.keySet()) {
					int val = maxMap.get(temp);
					if (max < val) {
						max = val;
						key = temp;
					}
				}
				log.info("========================================职工年度考核评级：分数=" + max + ",评级：" + key);
				map.put("glbdef8", key);
				sendData.add(MapToLowerCaseUtils.mapToLower(map));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			log.info("职工年度考核登记表, \n推送数据：" + JSONArray.toJSONString(sendData));
			BatchInsertAnnualAssessVO batchInsertAnnualAssessVO4 = new BatchInsertAnnualAssessVO();
			batchInsertAnnualAssessVO4.setString(JSONArray.toJSONString(sendData));
			BatchInsertAnnualAssessVOResponse rs = iVacationServiceStub
					.BatchInsertAnnualAssessVO(batchInsertAnnualAssessVO4);
			// 更新抛送数据
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("=================职工年度考核登记表=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCBatchInsertNewEmployeeVO()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/**
	 * 供应商单据
	 * 
	 * @param parmas
	 */
	public void sendTONCSupplierStatus(Map<String, Object> parmas) {
		String sql = "";
		try {
			if (StringUtils.equals(MapUtils.getString(parmas, "type"), "y")) {
				// 合格供应商调整表
				sql = this.freemarkFlowManager.fltTemplateIntoString("datasync/supplie/SH_SUPPLIE_002_SQL.ftl", parmas);
			} else {
				// 供应商绩效评价表
				sql = this.freemarkFlowManager.fltTemplateIntoString("datasync/supplie/SH_SUPPLIE_003_SQL.ftl", parmas);
			}
			log.info("=================供应商单据SQL:" + sql);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			log.info("供应商单据, \n推送数据：" + JSON.toJSONString(MapToLowerCaseUtils.listMapToLower(array)));
			busiWebServiceItfStub = new LyBusiWebServiceItfStub();
			SupplierStatus supplierStatus2 = new SupplierStatus();
			if (!array.isEmpty()) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("supplierCode", MapUtils.getString(array.get(0), "supplierCode"));
				map.put("supplierName", MapUtils.getString(array.get(0), "supplierName"));
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
				supplierStatus2.setString(JSON.toJSONString(map));
				SupplierStatusResponse rs = busiWebServiceItfStub.supplierStatus(supplierStatus2);
				// 更新抛送数据
				logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
				log.info("=================供应商单据====================\n" + rs.get_return());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCSupplierStatus()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}

	}

	/**
	 * 合同付款申请单
	 * @param parmas
	 */
	public void sendTONCApply(Map<String, Object> parmas) {
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_HT_FK_0001_SQL.ftl", parmas);
			log.info("=========shkk 合同付款申请单SQL:" + sql);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			log.info("合同付款申请单, \n推送数据：" + JSON.toJSONString(MapToLowerCaseUtils.listMapToLower(array)));
			for (Map<String, Object> map : array) {
				// 抛送数据写入日志底表 第一次添加
				if(StringUtils.equals(MapUtils.getString(parmas, "isAdd"), "yes")){
					logManageImpl.sendLog(parmas, JSON.toJSONString(map));
				}
			}
			ISyncApplyStub iSyncApplyStub = new ISyncApplyStub();
			Apply apply0 = new Apply();
			apply0.setString(JSONArray.toJSONString(MapToLowerCaseUtils.listMapToLower(array)));
			ApplyResponse rs = iSyncApplyStub.apply(apply0 );
			// 更新抛送数据
			logManageImpl.updateLog(parmas, JSON.toJSONString(rs));
			log.info("===============合同付款申请单====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCApply()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		} 
		
	}
	
	/**
	 * 考勤数据
	 */
	public void sendTONCVacationInsert() {
		// TODO 正式上线修改sql 查询的数据范围 ，开启定时任务
		try {
			String sql = this.freemarkFlowManager.fltTemplateIntoString("sql/workOrSkill/SELECT_KAOQIN_SQL.ftl", null);
			List<Map<String, Object>> array = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> listItems = new ArrayList<>();
			for (Map<String, Object> map : array) {
				map.put("date_year", DateFormatUtils.format(new Date(), "yyyy"));
				map.put("date_month", DateFormatUtils.format(new Date(), "MM"));
				map.put("sick_leave", "0"); // 病假
				map.put("personal_leave", "0"); // 事假
				map.put("marriage_leave", "0"); // 婚假
				map.put("home_leave", "0"); // 探亲假
				map.put("maternity_leave", "0"); // 产假
				map.put("days_off", "0"); // 调休
				map.put("escort_leave", "0"); // 陪护假
				map.put("female_leave", "0"); // 女工假
				map.put("funeral_leave", "0"); // 丧假
				map.put("official_holiday", "0"); // 年休假
				map.put("medical_leave", "0"); // 医疗期
				map.put("injury_leave", "0"); // 工伤
				map.put("outwork", "0"); // 出差
				String tempSql = this.freemarkFlowManager
						.fltTemplateIntoString("sql/workOrSkill/SELECT_KAOQIN_FORS_SQL.ftl", map);
				log.info("考勤月度数据抛送NC  SQL:" + tempSql);
				List<Map<String, Object>> temps = this.jdbcTemplate.queryForList(tempSql);
				for (Map<String, Object> map2 : temps) {
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "4266245001256978587")) {
						// 事假
						map.put("personal_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "201991198333487644")) {
						// 病假
						map.put("sick_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "2337141173293959554")) {
						// 产假
						map.put("maternity_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "-3824759628419871310")) {
						// 婚假
						map.put("marriage_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "7838857091659091383")) {
						// 探亲假
						map.put("home_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "-1029162416825351279")) {
						// 调休
						map.put("days_off", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "-2155386451255276558")) {
						// 丧假
						map.put("funeral_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "5770326202982679224")) {
						// 陪护假
						map.put("escort_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "7777434938787841435")) {
						// 女工假
						map.put("female_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "-7806467008713309058")) {
						// 年休假
						map.put("official_holiday", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "7178125781717436154")) {
						// 医疗期
						map.put("medical_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "5412711510151089863")) {
						// 工伤
						map.put("injury_leave", MapUtils.getString(map2, "num"));
					}
					if (StringUtils.equals(MapUtils.getString(map2, "type"), "5589527824166766184")) {
						// 出差
						map.put("outwork", MapUtils.getString(map2, "num"));
					}
				}
				listItems.add(MapToLowerCaseUtils.mapToLower(map));
			}
			iVacationServiceStub = new IPsndocInfoServiceStub();
			log.info("考勤月度数据抛送NC：" + JSONArray.toJSONString(listItems));
			VacationInsert vacationInsert0 = new VacationInsert();
			vacationInsert0.setString(JSONArray.toJSONString(listItems));
			VacationInsertResponse rs = iVacationServiceStub.VacationInsert(vacationInsert0);
			log.info("=================考勤月度数据=====================\n" + rs.get_return());
		} catch (Exception e) {
			e.printStackTrace();
			log.info("=============NC接口调用出错：sendTONCVacationInsert()");
			log.info("=============NC接口调用出错==============\n" + e.getMessage());
		}
	}

	/* 数字档案系统数据推送 */

	/**
	 * 向数字档案系统推送 流程数据意见结果
	 * 
	 * @param parmas
	 */
	public void sendTODOCArchives(Map<String, Object> parmas) {
		// TODO 等待数字档案接口
	}

	@Override
	public boolean beforeGrabData() {
		log.info("==>> kk 考勤数据推送 start =============" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		sendTONCVacationInsert();
		log.info("==>> kk 考勤数据推送   end  =============" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		return false;
	}

	@Override
	public boolean grabData() {
		return false;
	}

	@Override
	public boolean addData() {
		return false;
	}

	@Override
	public boolean updateData() {
		return false;
	}

	@Override
	public boolean deleteData() {
		return false;
	}

}
